package com.takeoutOrder.server.service.impl;

import java.util.List;

import com.takeoutOrder.common.core.domain.entity.SysUser;
import com.takeoutOrder.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.takeoutOrder.server.mapper.AddressBookMapper;
import com.takeoutOrder.server.domain.AddressBook;
import com.takeoutOrder.server.service.IAddressBookService;

/**
 * 地址簿Service业务层处理
 *
 * @author linzechen
 * @date 2024-11-27
 */
@Service
public class AddressBookServiceImpl implements IAddressBookService {
    @Autowired
    private AddressBookMapper addressBookMapper;

    /**
     * 查询地址簿
     *
     * @param id 地址簿主键
     * @return 地址簿
     */
    @Override
    public AddressBook selectAddressBookById(Long id) {
        return addressBookMapper.selectAddressBookById(id);
    }

    /**
     * 查询地址簿列表
     *
     * @param addressBook 地址簿
     * @return 地址簿
     */
    @Override
    public List<AddressBook> selectAddressBookList(AddressBook addressBook) {
        return addressBookMapper.selectAddressBookList(addressBook);
    }

    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * 新增地址簿
     *
     * @param addressBook 地址簿
     * @return 结果
     */
    @Override
    public int insertAddressBook(AddressBook addressBook) {
        SysUser sysUser = sysUserMapper.selectUserById(addressBook.getUserId());
        addressBook.setSex(sysUser.getSex());
        addressBook.setConsignee(sysUser.getNickName());
        return addressBookMapper.insertAddressBook(addressBook);
    }

    /**
     * 修改地址簿
     *
     * @param addressBook 地址簿
     * @return 结果
     */
    @Override
    public int updateAddressBook(AddressBook addressBook) {
        return addressBookMapper.updateAddressBook(addressBook);
    }

    /**
     * 批量删除地址簿
     *
     * @param ids 需要删除的地址簿主键
     * @return 结果
     */
    @Override
    public int deleteAddressBookByIds(Long[] ids) {
        return addressBookMapper.deleteAddressBookByIds(ids);
    }

    /**
     * 删除地址簿信息
     *
     * @param id 地址簿主键
     * @return 结果
     */
    @Override
    public int deleteAddressBookById(Long id) {
        return addressBookMapper.deleteAddressBookById(id);
    }
}
